package com.zhongyu.scheduler.provider.apiimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhongyu.comm.api.TaskApi;
import com.zhongyu.comm.pojo.Task;
import com.zhongyu.scheduler.provider.mapper.TaskMapper;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@RestController
public class TaskApiImpl implements TaskApi {
    @Resource
    protected TaskMapper taskMapper;
    @Override
    public List<Task> findByStatusAndOvertimeBefore(int status, LocalDateTime overtimeBefore, int limit) {
        QueryWrapper<Task> queryWrapper= Wrappers.query();
        queryWrapper.eq("status",status)
                .ge("overtime",overtimeBefore)
                .orderByAsc("create_time","update_time")
                .last(" limit "+limit);

        return taskMapper.selectList(queryWrapper);
    }

    @Override
    public int updateTaskVersion(String taskId, Integer taskVersion) {
        return  taskMapper.updateTaskVersion(taskId,taskVersion);
    }

    @Override
    public int updateStatus(String taskId, Integer status, LocalDateTime updateTime) {
        return taskMapper.updateStatus(taskId,status,updateTime);
    }

    @Override
    public int updateTryCountByTaskId(String taskId, LocalDateTime updateTime) {
        return taskMapper.updateTryCountByTaskId(taskId,updateTime);
    }

    @Override
    public int updateErrormsg(String taskId,String errormsg, LocalDateTime updateTime) {
        return taskMapper.updateRrrormsg(taskId,errormsg,updateTime);
    }


}
